package com.qidian.tcba.admin.service.impl;


import com.qidian.tcba.admin.model.dto.systemAdmin.ParkLotOrgDTO;
import com.qidian.tcba.admin.model.dto.systemAdmin.ParkLotOrgManageListDTO;
import com.qidian.tcba.admin.model.entity.Orgnization;
import com.qidian.tcba.admin.service.OrgnizationService;
import com.qidian.tcba.dao.OrgnizationMapper;
import com.qidian.tcba.utils.BeanMapper;
import com.qidian.tcba.utils.BusinessException;
import com.qidian.tcba.utils.Message;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 单位表 服务实现类
 * </p>
 *
 * @author 冯永龙
 * @since 2021-07-06
 */
@Service
public class OrgnizationServiceImpl implements OrgnizationService {
    @Autowired
    private OrgnizationMapper orgnizationMapper;

    @Override
    public List<ParkLotOrgManageListDTO> getParkLotOrgManageList(Integer districtId, String name, Integer status) {
        List<Orgnization> parkLotOrgManageList = orgnizationMapper.getParkLotOrgManageList(districtId, name, status);
        return BeanMapper.mapList(parkLotOrgManageList, ParkLotOrgManageListDTO.class);
    }

    @Override
    public boolean addOrg(ParkLotOrgDTO parkLotOrgDTO) {
        Integer id = orgnizationMapper.getOrgIdByName(parkLotOrgDTO.getName());
        if (id != null) {
            throw new BusinessException(new Message("DB.SELECT_SUCCESS","公司名称已存在！"));
        } else {
            Orgnization orgnization = BeanMapper.map(parkLotOrgDTO, Orgnization.class);
            orgnization.setType(1);
            orgnization.setStatus(1);
            return orgnizationMapper.insert(orgnization) == 1;
        }
    }

    @Override
    public boolean updateOrgStatus(int status, int id) {
        return orgnizationMapper.updateStatusById(status, id) == 1;
    }
}
